<?php
    include 'include/function.php';
    valid_user();
    if (empty($_GET['run_id']))
        $errorMsg = "Run ID cannot be null";
    else if (empty($_GET['problem']))
        $errorMsg = "Problem title cannot be null";
    $tcode = get_code($_GET['run_id'], $_SESSION['user_id']);
    if (empty($tcode))
        $errorMsg = "You cannot view this code";
    if (!empty($errorMsg))
        header("Location: error?error=" . urlencode($errorMsg));
    $code = htmlspecialchars($tcode['code']);
    $language = $tcode['language'];
    $result = $tcode['result'];
    $submit_time = $tcode['submit_time'];
    $problem = $_GET['problem'];
    $user_id = $_SESSION['user_id'];
    include 'include/header.php';
    $script_name = array('C++' => 'sh_cpp', 'C' => 'sh_c', 'Java' => 'sh_java', 'Pascal' => 'sh_pascal');
?>
<link type="text/css" rel="stylesheet" href="style/sh.css"></link>
<script language="javascript" src="common/sh_main.js"></script>
<script language="javascript" src="common/<?php echo $script_name[$language]; ?>.js"></script>
<script language="javascript">
window.onload = function () {
    sh_highlightDocument();
}
</script>
<title>Source Code</title>
    <div id="headline">
        <div class="wrapper">
            <h2>Source Code</h2>
        </div>
    </div>
<div id="pagebody">
	<div class="wrapper">
        <div class="notice">
            <?php
                echo "<strong>Problem: </strong>$problem&nbsp;&nbsp;";
                echo "<strong>User: </strong>$user_id<br/>";
                echo "<strong>Submit Time: </strong>$submit_time<br/>";
                echo "<strong>Language: </strong>$language&nbsp;&nbsp;";
                echo "<strong>Result: <span style=\"color:{$STATUS_COLOR[$result]}\">$result</span></strong><br/>";
            ?>
        </div>
        <pre name="code" class="<?php echo $script_name[$language] ?>"><?php echo $code;?></pre>
    </div>
</div>

<?php
    include 'include/footer.php';
?>
